package simulateOS.utils;

import javafx.animation.AnimationTimer;
import javafx.scene.control.Label;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import simulateOS.controller.ProcessPageController;

import javax.annotation.Resource;

/**
 * 用于系统运行时间的计时器
 * <p>Date: 2022/10/31
 * <p>Time: 19:20
 *
 * @Author SillyBaka
 **/
@Component
public class RuntimeTimer extends AnimationTimer {
    @Resource
    private ProcessPageController processPageController;

    private long startTime;
    private double curTime;

    private Label runTimeLabel;

    @Override
    public void handle(long now) {
        if(startTime == 0){
            startTime = now;
        }
        if(runTimeLabel == null){
            runTimeLabel = processPageController.getRunTimeLabel();
        }
        curTime = ((now-startTime)*1e-9);
        runTimeLabel.setText(String.valueOf(curTime));
    }

    public double getCurTime() {
        return curTime;
    }
}
